﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SpaceSquirrel
{
	public class DeathOverrideScene : GameSceneBase
	{
		private PlayScene bg;
		private Context context;
		private string type;
		private int counter;
		private double vy;

		// type = "lava", "collapse", "fall"
		public DeathOverrideScene(PlayScene bg, string type)
			: base()
		{
			this.bg = bg;
			this.context = bg.Context;
			this.context.LifeMeter = 0;
			this.type = type;
			this.counter = 0;
			this.bg.Player.deathState = type;
			this.vy = -10;
			if (type == "fall")
			{
				this.vy = bg.Player.vy;
			}
			else if (type == "lava")
			{
				SoundManager.PlayNoise("lava_roast");
			}

		}

		public override void ProcessInput(List<MyEvent> events, Dictionary<string, bool> pressedActions)
		{
			// There is nothing you can do
		}

		public override void Update()
		{
			if (this.counter == 0)
			{
				JukeBox.EnsureSong("death");
			}

			this.counter++;
			this.vy += 1;
			if (this.type == "lava" || this.type == "fall")
			{
				this.bg.Player.modelY += this.vy;
				this.bg.Player.y = (int)this.bg.Player.modelY;
			}

			if (this.counter > 100)
			{
				this.context.LifeMeter = 10;
				this.context.Lives--;
				if (this.context.Lives == 0)
				{
					this.context.Lives = 3;
					this.Next = new GameOverScene(this.context);
				}
				else
				{
					this.Next = new ReadyScene(this.bg, this.context);
				}
			}
		}

		public override void Render(TuxedoLib.Image screen, int renderCounter)
		{
			this.bg.Render(screen, renderCounter);
		}
	}
}
